package com.nowcoder.面试必刷101;


/**
 * @Description:
 * @author： yeswater
 * @create： 2024/6/13
 */

public class BM93 {
	public static void main(String[] args) {
		//int[] arr = {1,7,3,2,4,5,8,2,7};
		//int[] arr = {2,2};
		//int[] arr = {5,4,3,2,1,5};
		int[] arr = {6,4,3,1,4,6,99,62,1,2,6};
		System.out.println(maxArea(arr));
	}
	
	static public int maxArea(int[] height) {
		// write code here
		if (height == null || height.length < 2) {
			return 0;
		}
		int max = 0;
		int i = 0, j = height.length - 1;
		while (i < height.length && j >= 0 && i < j) {
			max = Math.max(max, (j - i) * Math.min(height[i], height[j]));
			if(height[i] < height[j]) {
				i++;
			} else {
				j--;
			}
		}
		
		
		return max;
		
		
	}
}
